/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DB;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author weidas
 */
@Entity
@Table(name = "StatusMessage")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "StatusMessage.findAll", query = "SELECT s FROM StatusMessage s"),
    @NamedQuery(name = "StatusMessage.findById", query = "SELECT s FROM StatusMessage s WHERE s.statusMessagePK.id = :id"),
    @NamedQuery(name = "StatusMessage.findByText", query = "SELECT s FROM StatusMessage s WHERE s.text = :text"),
    @NamedQuery(name = "StatusMessage.findByTmeposted", query = "SELECT s FROM StatusMessage s WHERE s.tmeposted = :tmeposted"),
    @NamedQuery(name = "StatusMessage.findBySenderId", query = "SELECT s FROM StatusMessage s WHERE s.statusMessagePK.senderId = :senderId")})
public class StatusMessage implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected StatusMessagePK statusMessagePK;
    @Column(name = "text")
    private String text;
    @Basic(optional = false)
    @Column(name = "tmeposted")
    @Temporal(TemporalType.TIMESTAMP)
    private Date tmeposted;
    @JoinColumn(name = "sender_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private User user;

    public StatusMessage() {
    }

    public StatusMessage(StatusMessagePK statusMessagePK) {
        this.statusMessagePK = statusMessagePK;
    }

    public StatusMessage(StatusMessagePK statusMessagePK, Date tmeposted) {
        this.statusMessagePK = statusMessagePK;
        this.tmeposted = tmeposted;
    }

    public StatusMessage(int id, int senderId) {
        this.statusMessagePK = new StatusMessagePK(id, senderId);
    }

    public StatusMessagePK getStatusMessagePK() {
        return statusMessagePK;
    }

    public void setStatusMessagePK(StatusMessagePK statusMessagePK) {
        this.statusMessagePK = statusMessagePK;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getTmeposted() {
        return tmeposted;
    }

    public void setTmeposted(Date tmeposted) {
        this.tmeposted = tmeposted;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (statusMessagePK != null ? statusMessagePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof StatusMessage)) {
            return false;
        }
        StatusMessage other = (StatusMessage) object;
        if ((this.statusMessagePK == null && other.statusMessagePK != null) || (this.statusMessagePK != null && !this.statusMessagePK.equals(other.statusMessagePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.StatusMessage[ statusMessagePK=" + statusMessagePK + " ]";
    }
    
}
